var http = require('http'); 
var fs = require('fs');
var url = require('url');

http.createServer(function (req, res) {
    var pathname = url.parse(req.url).pathname,
        ext = pathname.match(/(\.[^.]+|)$/)[0];
        switch(ext) {
            case '.css':
            case '.js':
                fs.readFile(req.url.slice(1), 'utf-8', function (err, data) {
                    if ( err ) throw err;
                    res.writeHead(200, {
                        'Content-Type': { 
                            '.css': 'text/css',
                            '.js' : 'application/javascript' 
                        }[ext]
                    });
                    res.write(data);
                    res.end();
                });
                break;
            default:
                fs.readFile('static/template/todos/index.html', 'utf-8',
                function ( err, data ) {
                    if ( err ) throw err;
                    res.writeHead(200, { 'Content-Type': 'text/html' });
                    res.write(data);
                    res.end();
                });
        }
}).listen(8000, "192.168.1.8");
console.log('Server running at http://192.168.1.8:8000/');
